package Servlet2;




import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;

@WebServlet("/dididi07")
public class Demo07 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String realPath = getServletContext().getRealPath("注册页面/响应图片.jpg");
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(realPath));
        ServletOutputStream sos = resp.getOutputStream();
//        循环读写
        byte[] bytes = new byte[1024];
        int len;
        while((len=bis.read(bytes))!=-1){
            sos.write(bytes,0,len);
        }
        bis.close();
        sos.close();
    }
}


